﻿using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
namespace ShowRoom
{
    public class Mupload
    {
        public const string UploadAllowedPicture = "jpg,png,gif,jpge,bmp";
        public const string UploadAllowedDoc = "png,jpg,gif,bmp,pdf,doc,xls";
        public const string UploadDaotao = "jpg,gif,bmp,pdf,doc,dot,xls,rar,zip" + "flv,mpg,mpeg,avi,wmf,wmv,mov";

        public const string UploadClip = "mpg,mpeg,avi,wmf,wmv,mov,flv";
        public static string CheckUpload(string strFileName, string _uploadAllowedFileTypes, int FileSizeUp, int FileSize)
        {
            string strFileExt = Strings.Mid(strFileName,Strings.InStrRev(strFileName, ".",-1,CompareMethod.Text) + 1);

            if (Strings.InStr(_uploadAllowedFileTypes, strFileExt, CompareMethod.Text) != 0)
            {
                if (FileSizeUp < FileSize)
                {
                    return "";
                }
                else
                {
                    return "Dung lượng file không dúng";                   	
                }
            }
            else
            {
               // return "file phải có dạng: "  + _uploadAllowedFileTypes;
                return ("<script>alert('file phải có dạng:jpg,gif,bmp')</script>");
            }
        }
        public static bool CheckHinh(string link, string _uploadAllowedFileTypes)
        {
            string strFileExt = Strings.Mid(link, Strings.InStrRev(link, ".",- 1, CompareMethod.Text) + 1);
            if (Strings.InStr(_uploadAllowedFileTypes, strFileExt, CompareMethod.Text) != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public string GetItemSequence(string SUP, int bulletID, string bulletValue)
        {
            
            string seqNo = "" ;

            try
            {
                int charVal = 0;
                switch (bulletID)
                {
                    case 5:
                        seqNo = Convert.ToChar(bulletValue).ToString();
                        charVal = Strings.Asc(Convert.ToChar(seqNo)) + Convert.ToInt32(SUP) - 1;
                        seqNo = Strings.Chr(charVal).ToString();
                        break;
                    case 3:
                        seqNo = bulletValue;
                        int seqNo1 = Convert.ToInt32(seqNo) + Convert.ToInt32(SUP) - 1;
                       
                        break;
                    case 6:
                        seqNo = Convert.ToChar(bulletValue).ToString();
                        charVal = Strings.Asc(Convert.ToChar(seqNo)) + Convert.ToInt32(SUP) - 1;
                        seqNo = Strings.Chr(charVal).ToString();
                        break;
                    case 1:
                        seqNo = bulletValue;
                       // seqNo = Convert.ToInt32(seqNo) + Convert.ToInt32(SUP) - 1;
                        seqNo = ToRoman(Convert.ToInt32(seqNo));
                        break;
                    case 2:
                        seqNo = bulletValue;
                        //seqNo = Convert.ToInt32(seqNo) + Convert.ToInt32(SUP) - 1;
                        seqNo = ToRoman(Convert.ToInt32(seqNo)).ToLower();
                        break;
                }
            }
            catch (Exception ex)
            {
            }
            return seqNo;
        }
        public static string ToRoman(int number)
        {
            if (-9999 >= number || number >= 9999)
            {
                throw new ArgumentOutOfRangeException("number");
            }

            if (number == 0)
            {
                return "NUL";
            }

            StringBuilder sb = new StringBuilder(10);

            if (number < 0)
            {
                sb.Append('-');
                number *= -1;
            }

            string[,] table = new string[,] { 
        { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" }, 
        { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" }, 
        { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
        { "", "M", "MM", "MMM", "M(V)", "(V)", "(V)M", 
                                          "(V)MM", "(V)MMM", "M(X)" } 
    };

            for (int i = 1000, j = 3; i > 0; i /= 10, j--)
            {
                int digit = number / i;
                sb.Append(table[j, digit]);
                number -= digit * i;
            }

            return sb.ToString();
        }

        public static string CheckUpDaotao(string link, int FileSize)
        {

            if (_FileType(Path.GetExtension(link)) == "1")
            {
                if (FileSize < 25000)
                {
                    return "";
                }
                else
                {
                    return "Dung lượng file không dúng, phải nhỏ hơn 200KB";
                }
            }
            else if (_FileType(Path.GetExtension(link)) == "2" | _FileType(Path.GetExtension(link)) == "3")
            {
                if (FileSize < 2500000)
                {
                    return "";
                }
                else
                {
                    return "Dung lượng file không dúng, phải nhỏ hơn 2MB";
                }
            }
            else
            {
                return "file phải có dạng: " + UploadDaotao;
            }
        }  
        public static string _FileType(string fileExtension)
{
	switch (Strings.LCase(fileExtension)) {
		case ".gif":
		case ".jpg":
		case ".png":
		case ".bmp":
			return "1";
		case ".xls":
		case ".xlt":
		case ".doc":
		case ".dot":
		case ".pdf":
		case ".zip":
		case ".rar":
		case ".ppt":
		case ".pps":
		case ".pot":
		case ".mht":
		case ".htm":
		case ".html":
			return "2";
		case ".flv":
		case ".mpg":
		case ".mpeg":
		case ".avi":
		case ".wmf":
		case ".wmv":
		case ".mov":
			return "3";
		default:
			return "4";
	}
}

}
}
